﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
    x:Class="EIA.SLClient.Utility.Controls.EditableTreeControl"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" BorderThickness="1">
	<UserControl.Resources>
		<sdk:HierarchicalDataTemplate x:Key="ViewDataTemplate" ItemsSource="{Binding Children}">
			<Grid>
				<TextBlock Margin="4,0" TextWrapping="Wrap" Text="{Binding Text}" d:LayoutOverrides="Width, Height" VerticalAlignment="Center"
					MouseRightButtonDown="TreeViewMain_MouseRightButtonDown"
					MouseRightButtonUp="TreeViewMain_MouseRightButtonUp"
					MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown"/>
			</Grid>
		</sdk:HierarchicalDataTemplate>
		<sdk:HierarchicalDataTemplate x:Key="OptDataTemplate" ItemsSource="{Binding Children}">
			<Grid>
				<StackPanel Orientation="Horizontal">
					<TextBlock  Margin="4,0" TextWrapping="Wrap" Text="{Binding Text}" VerticalAlignment="Center"
						MouseRightButtonDown="TreeViewMain_MouseRightButtonDown"
						MouseRightButtonUp="TreeViewMain_MouseRightButtonUp"
						MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown"/>
					<HyperlinkButton Content="添加" Margin="16,0,8,0" Click="AddButton_Click" VerticalAlignment="Center"/>
					<HyperlinkButton Content="修改" Margin="8,0" Click="EditButton_Click" VerticalAlignment="Center"/>
					<HyperlinkButton Content="删除" Margin="8,0" Click="DeleteButton_Click" VerticalAlignment="Center"/>
				</StackPanel>
			</Grid>
		</sdk:HierarchicalDataTemplate>
	</UserControl.Resources>
	<Grid x:Name="LayoutRoot">
		<toolkit:TreeViewDragDropTarget HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AllowDrop="True" 
			ItemDroppedOnSource="TreeViewDragDropTarget_ItemDroppedOnSource" 
			ItemDroppedOnTarget="TreeViewDragDropTarget_ItemDroppedOnTarget">
			<sdk:TreeView x:Name="TreeViewMain" ItemTemplate="{StaticResource ViewDataTemplate}"
				MouseRightButtonDown="TreeViewMain_MouseRightButtonDown"
				MouseRightButtonUp="TreeViewMain_MouseRightButtonUp"
				MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown"
                MouseLeave="TreeViewMain_MouseLeave"
                MouseEnter="TreeViewMain_MouseEnter"
				SelectedItemChanged="TreeViewMain_SelectedItemChanged" Background="#00FFFFFF" BorderThickness="0"/>
		</toolkit:TreeViewDragDropTarget>
		<Canvas>
			<Popup x:Name="ContextMenu" Visibility="Collapsed">
				<Border BorderThickness="1" Width="100" BorderBrush="Black" Background="White" Padding="4">
					<StackPanel> 
						<HyperlinkButton Content="添加" Padding="4" x:Name="AddButton" Click="AddButton_Click" /> 
						<HyperlinkButton Content="修改" Padding="4" x:Name="EditButton" Click="EditButton_Click"/> 
						<HyperlinkButton Content="删除" Padding="4" x:Name="DeleteButton" Click="DeleteButton_Click"/> 
					</StackPanel>
				</Border>
			</Popup>
		</Canvas> 
	</Grid>
</UserControl>
